import type { CartItem } from "@/types/cart"
import { http } from "@/utils/request"

/**
 * 加入购物车
 * @param data 
 * @returns 
 */
export const addMemberCartAPI = (data: { skuId: string, count: number }) => {
  return http({
    url: '/member/cart',
    method: "POST",
    data
  })
}
/**
 * 获取购物车列表
 * @returns 
 */
export const getCartListAPI = () => {
  return http<CartItem[]>({
    url: '/member/cart',
    method: 'GET'
  })
}
/**
 * 删除购物车单品
 * @param data 
 * @returns 
 */
export const deleteCartAPI = (data: { ids: string[] }) => {
  return http({
    url: '/member/cart',
    method: 'DELETE',
    data
  })
}
/**
 * 修改购物车单品
 * @param skuId 选中状态 - 可选参数
 * @param data 商品数量 - 可选参数
 * @returns 
 */
export const updateCartBySkuId = (skuId: string, data: { selected?: boolean, count?: number }) => {
  return http<CartItem>({
    url: `/member/cart/${skuId}`,
    method: 'PUT',
    data
  })
}
/**
 * 购物车全选/取消全选
 * @param data 
 * @returns 
 */
export const checkedChangeAPI = (data: { selected: boolean }) => {
  return http({
    url: '/member/cart/selected',
    method: 'PUT',
    data
  })
}